<!--
 * @author hemengxia
 模板库管理--模板库列表
 -->
<template>
  <div id="template-lib-index">
    <el-collapse-transition>
      <div v-show="searchshow" class="course-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input
          v-model.trim="searchQuery.name"
          placeholder="请输入模板库名称搜索"
          class="search-input"
          @keyup.enter.native="handleFilter"
        />
        <div class="course-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
        </div>
      </div>
    </el-collapse-transition>
    <div class="btn-container">
      <div class="btn-container-title">
        <span>模板库管理</span>
      </div>
    </div>
    <section class="main-table">
      <v-table :list="list" tag="templateLibIndex" :list-loading="listLoading" :filter-column="filtercolumn">
        <el-table-column label="操作" fixed="right" align="center" min-width="100" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </v-table>

    </section>
  </div>
</template>

<script>
import permission from '@/directive/permission/index.js' // 权限判断指令
// eslint-disable-next-line no-unused-vars
import elDragDialog from '@/directive/el-drag-dialog'
import VTable from '@/components/Table'
import { queryTemplateBaseQuery } from '../api/index.js'
export default {
  name: 'TemplateLibIndex',
  components: {
    VTable
  },
  directives: {
    permission,
    elDragDialog
  },
  data() {
    return {
      submitloading: false,

      listQuery: {
        page: 1,
        pageSize: 10
      },

      searchshow: true,
      searchQuery: {
        name: ''
      },

      list: [],
      total: 0,
      listLoading: false

    }
  },

  created() {
    this.getList()
  },
  methods: {

    filtercolumn(scope, item) {
      return scope.row[item]
    },
    getList() {
      this.listLoading = true
      const param = { dictName: this.searchQuery.name }
      return new Promise((resolve, reject) => {
        queryTemplateBaseQuery(param).then(res => {
          this.listLoading = false
          this.list = res.data.data || []
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.page = 1
      for (const key in this.searchQuery) {
        this.searchQuery[key] = ''
      }
      this.getList()
    },

    handleUpdate(row) {
      const { dictName, dictValue } = row
      this.$router.push({ path: this.$filterPath('list'), query: { obj: JSON.stringify({ dictName, dictValue }) }})
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" type="text/scss">
$dark_gray: #bfced6;
// $mainColor: #18a5fd;

#template-lib-index {
  padding: 10px 20px 10px 10px;

  .course-search {
    background-color: #fff;
    padding: 0 10px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;

      &_login {
        font-size: 20px;
      }
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: "";
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .course-search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .course-search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .course-search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: "";
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .course-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .btn-container {
    display: flex;
    align-items: center;
    margin-top: 5px;
    margin-bottom: 5px;

    .btn-container-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      color: rgba(51, 51, 51, 1);
    }
  }
}
</style>
